<?php


namespace App\Admin\Renderable;


use App\Models\Config\SystemDictDatum;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class DictDatumTable extends LazyRenderable
{
    public function grid(): Grid
    {
        $key = request("key");
        $model = SystemDictDatum::where("dict_id",$key)->orderBy("sort");


        $grid =  Grid::make($model, function (Grid $grid) use($key){
            $grid->column('dict_label',"标签");
            $grid->column('dict_value',"值");
            $grid->column('state',"状态")->display(function (){
                return $this->state ? "<i class='fa feather icon-check text-green'></i>" :"<i class='fa feather icon-x text-red'></i>";
            });
            $grid->column('sort',"排序");
            /*$grid->column('is_default',"默认")->display(function ($item){
                return 2;
            });*/
            #$grid->column('remark',"备注");

            //$grid->quickSearch(['dict_label','dict_value']);

            $grid->paginate(10);
            $grid->disableActions();
            $grid->disableRowSelector();
            $grid->disableFilterButton();
        });

        /*$grid->quickCreate(function (Grid\Tools\QuickCreate $create)use($key) {
            $create->hidden("dict_id")->value($key);
            $create->text('dict_label')->required();
            $create->text('dict_value')->required();
            $create->select('state')->options(["0"=>"关闭","1"=>"开启"])->default(1)->required();

            $create->action("/diablo/config/dict-datum?dict_id=".$key);
        });*/

        return $grid;
    }
}
